package com.yang.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import org.junit.Test;

public class CreateGra {

	public static void createImg(int width, int height, OutputStream os,String str)
			throws IOException {
		BufferedImage bi = new BufferedImage(width, height,BufferedImage.TYPE_4BYTE_ABGR_PRE);
		Graphics2D g = bi.createGraphics();
		g.setFont(new Font(null, Font.PLAIN, 45));
		g.setColor(new Color(0, 0, 0, 0));
		g.fillRect(0, 0, width, height);
		g.setColor(Color.green);
		//g.drawString(str, width/4, height/2);
		g.drawString(str, 0/4, height/2);
		ImageIO.write(bi, "png", os);
	}
	@Test
	public void test(){
		try {
			String str="kdfjlskdjflskdfjsdklfjkjsdklfjlsdk";
			createImg(120, 129, new FileOutputStream("f://b.png"),str);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
